package com.lagou.edu.service.impl;

import com.lagou.code.entity.Code;
import com.lagou.code.mapper.CodeMapper;
import com.lagou.edu.service.CodeService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@Service
public class CodeServiceImpl implements CodeService {

    @Autowired
    private CodeMapper codeMapper;

    @Override
    public Integer validateCode(String email, String code) {
        Code codeEntity = codeMapper.findByEmail(email, code);
        if(codeEntity == null) {
            return 1;//错误
        } else if(codeEntity.getExpiretime().before(new Date())) {
            return 2;//超时
        } else {
            return 0;//正确
        }
    }
}
